package com.yanqu.road.server.cmd.banquet;

import com.yanqu.road.entity.banquet.UserBanquetData;
import com.yanqu.road.entity.banquet.UserCrossBanquetData;
import com.yanqu.road.entity.enums.eBanquetType;
import com.yanqu.road.pb.banquet.BanquetProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.banquet.BanquetMgr;
import com.yanqu.road.server.manger.banquet.CrossBanquetMgr;
import com.yanqu.road.server.pb.BanquetPb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

import java.util.Map;

//@Cmd(code = Protocol.S_BANQUET_LIST, desc = "请求宴会列表")
public class GetBanquetCmd extends AbstractCommand {

	private int banquetType;
	private int type;
	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		BanquetProto.BanquetListReq reqMsg = BanquetProto.BanquetListReq.parseFrom(packet.getBytes());
		banquetType = reqMsg.getBanquetType();
		type = reqMsg.getType();
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {

	}

	@Override
	public void sendData(GamePlayer player) {
		BanquetProto.BanquetListResp.Builder respMsg = BanquetProto.BanquetListResp.newBuilder();
		if(banquetType == eBanquetType.ServerNormalBanquet.getValue()){
			Map<String, UserBanquetData> banquets = BanquetMgr.getBanquetOpen(player,banquetType,false);
			Map<String, UserBanquetData> banquetQinjia = BanquetMgr.getBanquetOpen(player,banquetType,true);
			banquets.putAll(banquetQinjia);
			respMsg = BanquetPb.parseBanquetListRespMsg(player,banquets);

			/*if(type == 1){//普通的宴会
				respMsg = BanquetPb.parseBanquetListRespMsg(player,BanquetMgr.getBanquetOpen(player,banquetType,false));
			}else if(type == 2){//亲家的宴会
				respMsg = BanquetPb.parseBanquetListRespMsg(player,BanquetMgr.getBanquetOpen(player,banquetType,true));
			}*/
		}else if(banquetType == eBanquetType.ServerFeastBanquet.getValue()){
			Map<String, UserBanquetData> crossBanquets = BanquetMgr.getBanquetOpen(banquetType);
			respMsg = BanquetPb.parseBanquetListRespMsg(player,crossBanquets);
		}else if(banquetType == eBanquetType.CrossBanquet.getValue()){
			Map<String, UserCrossBanquetData> crossBanquets= CrossBanquetMgr.getBanquetOpen(eBanquetType.CrossBanquet.getValue());
			respMsg = BanquetPb.parseBanquetListRespMsgCross(player,crossBanquets);
		}else if(banquetType == eBanquetType.CrossUserBanquet.getValue()){
			Map<String, UserCrossBanquetData> crossBanquets= CrossBanquetMgr.getBanquetOpen(player,eBanquetType.CrossUserBanquet.getValue());
			respMsg = BanquetPb.parseBanquetListRespMsgCross(player,crossBanquets);
		}else{
			respMsg = BanquetPb.parseBanquetListRespMsg(player,BanquetMgr.getBanquetOpen(player,banquetType,false));
		}

		respMsg.setRet(ret);
		player.sendPacket(Protocol.U_BANQUET_LIST, respMsg);
	}
}
